/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projekt.zaliczeniowy.tkunit.assertions;

/**
 * All objects being compared must override their equals method in order for the
 * assertions to work properly
 *
 * @author Tomek
 */
public class Assertions {

    public static void assertEquals(Object expected, Object actual) {
        if(expected == null && actual == null)
            return;
        if(expected == null || actual == null)
            throw new AssertionError("It was: " + actual + " while it should be " + expected);
        if (!expected.equals(actual)) {
            throw new AssertionError("It was: " + actual + " while it should be " + expected);
        }
    }

    public static void assertEquals(int expected, int actual) {
        if (expected != actual) {
            throw new AssertionError("It was: " + actual + " while it should be " + expected);
        }
    }

    public static void assertEquals(long expected, long actual) {
        if (expected != actual) {
            throw new AssertionError("It was: " + actual + " while it should be " + expected);
        }
    }

    public static void assertEquals(float expected, float actual) {
        if (expected != actual) {
            throw new AssertionError("It was: " + actual + " while it should be " + expected);
        }
    }

    public static void assertEquals(double expected, double actual) {
        if (expected != actual) {
            throw new AssertionError("It was: " + actual + " while it should be " + expected);
        }
    }

    public static void assertEquals(float expected, float actual, float precission) {
        if (Math.abs(expected - actual) > Math.abs(precission)) {
            throw new AssertionError("It was: " + actual + " while it should be " + expected);
        }
    }

    public static void assertEquals(double expected, double actual, double precission) {
        if (Math.abs(expected - actual) > Math.abs(precission)) {
            throw new AssertionError("It was: " + actual + " while it should be " + expected);
        }
    }

    public static void assertTrue(boolean condition) {
        if (!condition) {
            throw new AssertionError("The condition should be true but was false");
        }
    }

    public static void assertFalse(boolean condition) {
        if (condition) {
            throw new AssertionError("The condition should be false but was false");
        }
    }

    public static void assertNull(Object object) {
        if (object != null) {
            throw new AssertionError("The object should be null but it wasn't");
        }
    }

    public static void assertNotNull(Object object) {
        if (object == null) {
            throw new AssertionError("The object should be not null but it was");
        }
    }

    public static void fail(String message) {
        throw new FailError(message);
    }

    public static void fail() {
        throw new FailError("This should not happen");
    }
}
